@extends('layouts.appManager')

@section('title')合作授权@endsection

@section('content')
<div class="container py-5" v-if="info">

    <br />

    <el-row :gutter="20">



        <el-col :span="10" :offset="0">
            <el-input type="text"  v-model="info.user_acc_cooperation" placeholder="邮箱地址">
                <template slot="prepend">授权合作人账号：</template>
            </el-input>
        </el-col>

        <el-col :span="10">
            <el-input type="number" min="0" max="100" step="1" v-model="info.cooperation_ratio">
                <template slot="prepend">分成比例：</template>
            </el-input>
        </el-col>

        <el-col :span="4">
            <el-button type="primary" @click="saveConfig()">保存</el-button>
        </el-col>

    </el-row>
    <br>
    <el-alert
        title=" 提示：删除授权合作人账号后保存，即为取消合作。"
        type="warning" show-icon>
    </el-alert>


</div>

@endsection
@section('script')

<script>
let serverId = '{{$id}}';

var app = new Vue({
    el: '#app',
    data: {
        serverId: parseInt(serverId),
        info:{},
    },
    mounted() {
        this.getInfo();
    },

    methods: {
        getInfo: function() {
            var t = this;
            post("/manager/server/cooperation/" + t.serverId + "/info", {}, res => {
                t.info = res.data;
            }, t);
        },
        saveConfig() {
            var t = this;
            post("/manager/server/cooperation/" + t.serverId + "/saveConfig", {
                acc: t.info.user_acc_cooperation,
                ratio: t.info.cooperation_ratio,
            }, res => {
                if (res.err!==0){
                    t.$message.error(res.msg);
                }else{
                    t.$message.success('保存成功');
                }
            }, t);
        },
    }
});
</script>
@endsection
